using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace LogNet6.Sqlite.Demo.Pages.Log;

public class IndexModel : PageModel
{
    [BindProperty(SupportsGet = true)]
    public int PageNo { get; set; } = 0;
    [BindProperty(SupportsGet = true)]
    public int PageSize { get; set; } = 10;
    [BindProperty(SupportsGet = true)]
    public int RemoveId { get; set; } = 0;

    public List<SqliteLoggerItem> Items { get; set; } = default!;
    public void OnGet([FromServices] ISqliteLoggerProcessor service)
    {
        if (RemoveId > 0)
            service.Remove(RemoveId);
        else if (RemoveId < 0)
            service.RemoveRange(-RemoveId);
        Items = service.GetLogs(PageNo, PageSize);
    }
}
